package com.rockerhieu.emojicon;

import java.util.ArrayList;
import com.rockerhieu.emojicon.EmojiAdapter.ViewHolder;
import com.rockerhieu.emojicon.emoji.Emojicon;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class EmojiAdapter1 extends BaseAdapter {

	private Context mContext;

	private ArrayList<Emojicon> citys;
	 private boolean mUseSystemDefault = false;
	public EmojiAdapter1(Context mContext ,boolean useSystemDefault) {
		this.mContext = mContext;
		 mUseSystemDefault = false;
	}

	public ArrayList<Emojicon> getCitys() {
		return citys;
	}

	public void setEmojicon(ArrayList<Emojicon> citys) {
		if(citys !=null&&citys.size()>0){
			Emojicon m=new Emojicon("");
			citys.add(m);
		}
		this.citys = citys;
	}

	@Override
	public int getCount() {
		return citys == null ? 0 : citys.size();
	}

	@Override
	public Object getItem(int position) {
		return citys == null ? null : citys.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("NewApi")
	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		View v = convertView;
        if (v == null) {
            v = View.inflate(mContext, R.layout.emojicon_item, null);
            ViewHolder holder = new ViewHolder();
            holder.icon = (EmojiconTextView) v.findViewById(R.id.emojicon_icon);
            holder.icon.setUseSystemDefault(mUseSystemDefault);
            v.setTag(R.id.tag_first,holder);
        }
        Emojicon emoji = (Emojicon) getItem(position);
        ViewHolder holder = (ViewHolder) v.getTag(R.id.tag_first);
        holder.icon.setText(emoji.getEmoji());
        v.setTag(R.id.tag_second,0);
        if(position==getCount()-1){
        	holder.icon.setBackgroundResource(R.drawable.emotion_del_normal);
        	 v.setTag(R.id.tag_second,1);
        }
       
        return v;
    }

    class ViewHolder {
        EmojiconTextView icon;
    }
}
